package com.koron.standard.jobStock.experiment.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.koron.standard.jobStock.experiment.bean.po.ExperimentParams;
import com.koron.standard.jobStock.experiment.mapper.ExperimentParamsMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 试验标准下工作环境参数(ExperimentParams)表服务实现类
 *
 * @author jzp
 * @since 2021-09-16
 */
@Service
public class ExperimentParamsService extends ServiceImpl<ExperimentParamsMapper, ExperimentParams> {

    public List<ExperimentParams> listByExperimentId(String id) {
        LambdaQueryWrapper<ExperimentParams> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ExperimentParams::getExperimentId, id);
        return list(wrapper);
    }

    public void removeByExperimentId(String experimentId) {
        if (StrUtil.isEmpty(experimentId)) {
            return;
        }
        LambdaQueryWrapper<ExperimentParams> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ExperimentParams::getExperimentId, experimentId);
        List<ExperimentParams> list = list(wrapper);
        removeByIds(list.stream().map(ExperimentParams::getId).collect(Collectors.toList()));
    }
}
